package io.renren.modules.examination.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.examination.entity.ExaminationPaperEntity;
import io.renren.modules.examination.service.ExaminationPaperService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author liuzhm
 * @email ztezhmliu@126.com
 * @date 2019-05-24 10:18:54
 */
@RestController
@RequestMapping("examination/paper")
public class ExaminationPaperController {
    @Autowired
    private ExaminationPaperService examinationPaperService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("examination:paper:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = examinationPaperService.getExaminationPaperList(params);
        System.out.println(page);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("course:student:info")
    public R info(@PathVariable("id") Integer id){
        ExaminationPaperEntity examinationPaper = examinationPaperService.selectById(id);

        return R.ok().put("examinationPaper", examinationPaper);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("course:student:save")
    public R save(@RequestBody ExaminationPaperEntity examinationPaper){
        examinationPaperService.insert(examinationPaper);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
  //  @RequiresPermissions("course:student:update")
    public R update(@RequestBody ExaminationPaperEntity examinationPaper){
        ValidatorUtils.validateEntity(examinationPaper);
        examinationPaperService.updateAllColumnById(examinationPaper);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
  //  @RequiresPermissions("course:student:delete")
    public R delete(@RequestBody Integer[] ids){
        boolean a = examinationPaperService.deleteAll(Arrays.asList(ids));
        if (a)
            return R.ok();
        else
            return R.error("删除过程中出现错误，请联系开发人员查看");
    }

}


